from django.urls import path
from snippets import views
from rest_framework.urlpatterns import format_suffix_patterns
from django.conf.urls import include
from rest_framework.routers import DefaultRouter
from snippets.views import SnippetViewSet,UserViewSet,api_root
# urlpatterns = [
#     path('snippets/', views.snippet_list),
#     path('snippets/<int:pk>', views.snippet_detail),
#
# ]
# urlpatterns = format_suffix_patterns(urlpatterns)

# urlpatterns = [
#     path('',views.api_root),
#     path('snippets/', views.SnippetList.as_view(),name='snippet-list'),
#     path('snippets/<int:pk>/', views.SnippetDetail.as_view(),name='snippet-detail'),
#     path('users/', views.UserList.as_view(),name='user-list'),
#     path('users/<int:pk>/', views.UserDetail.as_view(),name='user-detail'),
#     path('snippets/<int:pk>/highlight/', views.SnippetHighlight.as_view(),
#     name='snippet-highlight'),
#
# ]
# urlpatterns += [
#     path('api-auth/', include('rest_framework.urls')),
#
# ]
# urlpatterns = format_suffix_patterns(urlpatterns)

# 注释这部分是视图集
# snippet_list = SnippetViewSet.as_view({
#     'get': 'list',
#     'post': 'create'
# })
# snippet_detail = SnippetViewSet.as_view({
#     'get': 'retrieve',
#     'put': 'update',
#     'patch': 'partial_update',
#     'delete': 'destroy'
# })
# snippet_highlight = SnippetViewSet.as_view({
#     'get': 'highlight'
# }, renderer_classes=[renderers.StaticHTMLRenderer])
# user_list = UserViewSet.as_view({
#     'get': 'list'
# })
# user_detail = UserViewSet.as_view({
#     'get': 'retrieve'
# })
# urlpatterns = [
#     path('', api_root),  #为了在根路径超链接到不同的资源
#     path('snippets/', snippet_list,name='snippet-list'),
#     path('snippets/<int:pk>/', snippet_detail,name='snippet-detail'),
#     path('snippets/<int:pk>/highlight/',  snippet_highlight,name='snippet-highlight'),
#     path('users/', user_list,name='user-list'),
#     path('users/<int:pk>/', user_detail,name='user-detail'),
# ]
#
# # 为了让url支持json
# urlpatterns = format_suffix_patterns(urlpatterns)

# 使用了路由器
router = DefaultRouter()  # 帮我们做了list，detail的方法跳转对应
router.register(r'snippets', SnippetViewSet,basename="snippets")
router.register(r'users', UserViewSet,basename="users")

# The API URLs are now determined automatically by the router.
urlpatterns = [
    path('', include(router.urls)),
]